﻿using Super.Admin.Entities;
using Super.Admin.Models.UserRole;

namespace Super.Admin.Mappers
{
    /// <summary>
    /// UserRoleMapper 类用于在 UserRoleEntity 和 UserRoleModel 之间进行转换。
    /// </summary>
    public static class UserRoleMapper
    {
        /// <summary>
        /// 将 UserRoleEntity 转换为 UserRoleBaseModel。
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static UserRoleBaseModel ToBaseModel(this UserRoleEntity entity)
        {
            if (entity == null) return null;
            return new UserRoleBaseModel
            {
                UserId = entity.UserId,
                RoleId = entity.RoleId,
            };
        }
        /// <summary>
        /// 将 UserRoleEntity 转换为 UserRoleDetailModel。
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static UserRoleDetailModel ToDetailModel(this UserRoleEntity entity)
        {
            if (entity == null) return null;
            return new UserRoleDetailModel
            {
                UserId = entity.UserId,
                RoleId = entity.RoleId,
                User = entity.User?.ToBaseModel(),
                Role = entity.Role?.ToBaseModel()
            };
        }
        /// <summary>
        /// 将 UserRoleBaseModel 转换为 UserRoleEntity。
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static UserRoleEntity ToEntity(this UserRoleBaseModel model)
        {
            if (model == null) return null;
            return new UserRoleEntity
            {
                UserId = model.UserId,
                RoleId = model.RoleId,
            };
        }
        /// <summary>
        /// 将 UserRoleDetailModel 转换为 UserRoleEntity。
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static UserRoleEntity ToEntity(this UserRoleDetailModel model)
        {
            if (model == null) return null;
            return new UserRoleEntity
            {
                UserId = model.UserId,
                RoleId = model.RoleId,
            };
        }
        /// <summary>
        /// 将 UserRoleEntity 集合转换为 UserRoleBaseModel 集合。
        /// </summary>
        /// <param name="entities"></param>
        /// <returns></returns>
        public static IEnumerable<UserRoleBaseModel> ToBaseModels(this IEnumerable<UserRoleEntity> entities)
        {
            return entities?.Select(e => e.ToBaseModel()).ToList() ?? new List<UserRoleBaseModel>();
        }
        /// <summary>
        /// 将 UserRoleEntity 集合转换为 UserRoleDetailModel 集合。
        /// </summary>
        /// <param name="entities"></param>
        /// <returns></returns>
        public static IEnumerable<UserRoleDetailModel> ToDetailModels(this IEnumerable<UserRoleEntity> entities)
        {
            return entities?.Select(e => e.ToDetailModel()).ToList() ?? new List<UserRoleDetailModel>();
        }
        /// <summary>
        /// 将 UserRoleBaseModel 集合转换为 UserRoleEntity 集合。
        /// </summary>
        /// <param name="models"></param>
        /// <returns></returns>
        public static IEnumerable<UserRoleEntity> ToEntities(this IEnumerable<UserRoleBaseModel> models)
        {
            return models?.Select(m => m.ToEntity()).ToList() ?? new List<UserRoleEntity>();
        }
        /// <summary>
        /// 将 UserRoleDetailModel 集合转换为 UserRoleEntity 集合。
        /// </summary>
        /// <param name="models"></param>
        /// <returns></returns>
        public static IEnumerable<UserRoleEntity> ToEntities(this IEnumerable<UserRoleDetailModel> models)
        {
            return models?.Select(m => m.ToEntity()).ToList() ?? new List<UserRoleEntity>();
        }
    }
}